package com.inetools.gwt.gajaxs.client;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

/**
 * Model (JavaScriptObject) class for common data returned by google data API
 * Refer to the followings:
 * 	http://code.google.com/apis/gdata/docs/2.0/reference.html#DocumentFormat
 * 	http://code.google.com/apis/gdata/docs/2.0/elements.html#gdEventKind
 * @author ay
 */
public class GDataFeedModel extends JavaScriptObject {
	protected GDataFeedModel() {
	}
	
	// Definition for elements with sub-property --------------------------------------------------
	public static class Category extends JavaScriptObject {
		protected Category() {
		}
		/**
		 * Feed category scheme
		 * @return
		 */
		public final native String getScheme() /*-{
			return this.scheme;
		}-*/;
		/**
		 * Feed category
		 * @return
		 */
		public final native String getTerm() /*-{
			return this.term;
		}-*/;
	} // public static class Category extends JavaScriptObject
	public static class Author extends JavaScriptObject {
		protected Author() {
		}
		
		public final native String getEmail() /*-{
			if ( this.email) return this.email.$t;
			else return null;
		}-*/;
		public final native String getName() /*-{
			return this.name.$t;
		}-*/;
		public final native String getURI() /*-{
			if ( this.uri) return this.uri.$t;
			else return null;
		}-*/;
		
	} // public static class Author extends JavaScriptObject
	public static class Link extends JavaScriptObject {
		protected Link() {
		}
		
		public final native String getHref() /*-{
			return this.href;
		}-*/;
		/**
		 * When this value is "alternate", then href value points web page describing the event
		 * @return
		 */
		public final native String getRel() /*-{
			return this.rel;
		}-*/;
		public final native String getTitle() /*-{
			if ( this.title) return this.title;
			else return null;
		}-*/;
		public final native String getType() /*-{
			return this.type;
		}-*/;
	} // public static class Link extends JavaScriptObject
	
	public static class Generator extends JavaScriptObject {
		protected Generator() {
		}
		
		public final native String getGeneratorStr() /*-{
			return this.$t;
		}-*/;
		public final native String getURI() /*-{
			return this.uri;
		}-*/;
		public final native String getVersion() /*-{
			return this.version;
		}-*/;
	} // public static class Generator extends JavaScriptObject
	
	//TODO Could not find info for media$group.media$keywords, need to add getter for it once info is found.
	public static class MediaGourp extends JavaScriptObject {
		public static class Content extends JavaScriptObject {
			protected Content() {
			}
			
			public final native String getMedium() /*-{
				return this.medium;
			}-*/;
			public final native String getType() /*-{
				return this.type;
			}-*/;
			public final native String getUrl() /*-{
				return this.url;
			}-*/;
		} // public static class Content extends JavaScriptObject
		
		public static class Credit extends JavaScriptObject {
			protected Credit() {
			}
			
			public final native String getCredit() /*-{
				return this.$t;
			}-*/;
		} // public static class Credit extends JavaScriptObject
		
		public static class Thumbnail extends JavaScriptObject {
			protected Thumbnail() {
			}
			
			public final native int getHeight() /*-{
				return this.height;
			}-*/;
			
			public final native String getUrl() /*-{
				return this.url;
			}-*/;
			
			public final native int getWidth() /*-{
				return this.width;
			}-*/;
		} // public static class Thumbnail extends JavaScriptObject
		
		public static class Title extends JavaScriptObject {
			protected Title() {
			}
			
			public final native String getTitle() /*-{
				return this.$t;
			}-*/;
			
			public final native String getType() /*-{
				return this.type;
			}-*/;
		} // public static class Title extends JavaScriptObject
		
		protected MediaGourp() {
		}
		
		public final native JsArray<Content> getContents() /*-{
			return this.media$content;
		}-*/;
		
		public final native JsArray<Credit> getCredits() /*-{
			return this.media$credit;
		}-*/;
		
		public final native String getDescription() /*-{
			if ( this.media$description) return this.media$description.$t ? this.media$description.$t : null;
			else return null;
		}-*/;
		
		public final native JsArray<Thumbnail> getThumbnails() /*-{
			return this.media$thumbnail;
		}-*/;
		
		public final native Title getTitle() /*-{
			return this.media$title;
		}-*/;
		
	} // public static class MediaGourp
	
	
	public static class GDEntry extends JavaScriptObject {
		protected GDEntry() {
		}
		
		// Data API Entry Schema element ----------------------------------------------------------
		// Refer to http://code.google.com/apis/gdata/docs/2.0/reference.html#DocumentFormat
		public final native String getId() /*-{
			return this.id.$t;
		}-*/;
		public final native String getTitle() /*-{
			return this.title.$t;
		}-*/;
		public final native JsArray<Link> getLinks() /*-{
			return this.link;
		}-*/;
		public final native MediaGourp getMediaGroup() /*-{
			return this.media$group ? this.media$group : null;
		}-*/;
		public final native String getContent() /*-{
			return this.content.$t;
		}-*/;
		public final native JsArray<Author> getAuthors() /*-{
			return this.author;
		}-*/;
		public final native JsArray<Category> getCategories() /*-{
			return this.category;
		}-*/;
		public final native String getPublished() /*-{
			return this.published.$t;
		}-*/;
		public final native String getRights() /*-{
			if ( this.rights) return this.rights.$t ? this.rights.$t : null;
			else return null;
		}-*/;
		public final native String getSummary() /*-{
			if ( this.summary) return this.summary.$t ? this.summary.$t : null;
			else return null;
		}-*/;
		public final native String getUpdated() /*-{
			return this.updated.$t;
		}-*/;
		
		// ----------------------------------------------------------------------------------------
	}
	// --------------------------------------------------------------------------------------------
	
	// Data API feed schema element ---------------------------------------------------------------
	// Refer to http://code.google.com/apis/gdata/docs/2.0/reference.html#DocumentFormat
	/**
	 * Feed Title
	 */
	public final native String getTitle() /*-{
		return this.feed.title.$t;
	}-*/;
	/**
	 * Feed ID
	 * @return
	 */
	public final native String getId() /*-{
		return this.feed.id.$t;
	}-*/;
	/**
	 * Feed HTML link
	 * @return
	 */
	public final native JsArray<Link> getLinks() /*-{
		return this.feed.link;
	}-*/;
	/**
	 * Feed description
	 * @return
	 */
	public final native String getSubTitle() /*-{
		return this.feed.subtitle.$t;
	}-*/;
	/**
	 * Feed author
	 * @return
	 */
	public final native JsArray<Author> getAuthors() /*-{
		return this.feed.author;
	}-*/;
	/**
	 * Feed last update date
	 * @return
	 */
	public final native String getUpdated() /*-{
		return this.feed.updated.$t;
	}-*/;
	/**
	 * Feed category and category scheme
	 * @return
	 */
	public final native JsArray<Category> getCategories() /*-{
		return this.feed.category;
	}-*/;
	/**
	 * Feed generator
	 * @return
	 */
	public final native Generator getGenerator() /*-{
		return this.feed.generator;
	}-*/;
	// --------------------------------------------------------------------------------------------
	// Data API search-results feed schema element ------------------------------------------------
	// Refer to http://code.google.com/apis/gdata/docs/2.0/reference.html#DocumentFormat
	/**
	 * Number of Search Results
	 */
	public final native int getTotalResults() /*-{
		return this.feed.openSearch$totalResults.$t;
	}-*/;
	/**
	 * Search Result Start Index
	 * @return
	 */
	public final native int getStartIndex() /*-{
		return this.feed.openSearch$startIndex.$t;
	}-*/;
	/**
	 * Number of Search Results Per Page
	 * @return
	 */
	public final native int getItemsPerPage() /*-{
		return this.feed.openSearch$itemsPerPage.$t;
	}-*/;
	// --------------------------------------------------------------------------------------------
	
	// Data API Entry Schema element
	public final native JsArray<GDEntry> getGDEntries() /*-{
		return this.feed.entry;
	}-*/;
}
